package com.sabeot.library.hibernate.dto;

import java.util.Calendar;
import java.util.Date;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.MapsId;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;


@Entity
@Table(name = "app_user_details",schema="library")
public class UserDetails extends BasicDTO{

	@Column(name = "first_name", nullable = false)
	private String firstName;

	@Column(name = "last_name", nullable = false)
	private String lastName;

	@Column(name = "e_mail", nullable = true)
	private String eMail;

	@Column(name = "alt_e_mail", nullable = true)
	private String alternateEMail;

	@Column(name = "birth_date", nullable = true)
	@Temporal(TemporalType.DATE)
	private Date birthDate;

	@OneToOne
	@JoinColumn(name = "id")
	@MapsId
	private User user;

	@OneToMany(fetch = FetchType.LAZY, mappedBy = "userDetails")
	private Set<Address> addresses;
	
	/*
	 * Constructors
	 */

	public UserDetails() {
	}

	public UserDetails(String firstName, String lastName, String eMail,
			String alternateEMail, Date birthDate) {

		Date currentDate = Calendar.getInstance().getTime();
		this.modifyDate = currentDate;
		this.createDate = currentDate;
		this.firstName = firstName;
		this.lastName = lastName;
		this.eMail = eMail;
		this.alternateEMail = alternateEMail;
		this.birthDate = birthDate;

	}
	
	public UserDetails(String firstName, String lastName, String eMail,
			String alternateEMail, Date birthDate, User user) {

		Date currentDate = Calendar.getInstance().getTime();
		this.modifyDate = currentDate;
		this.createDate = currentDate;
		this.firstName = firstName;
		this.lastName = lastName;
		this.eMail = eMail;
		this.alternateEMail = alternateEMail;
		this.birthDate = birthDate;
		this.user = user;

	}

	/*
	 * Getters and Setters
	 */

	public String getFirstName() {
		return firstName;
	}

	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}

	public String getLastName() {
		return lastName;
	}

	public void setLastName(String lastName) {
		this.lastName = lastName;
	}

	public String geteMail() {
		return eMail;
	}

	public void seteMail(String eMail) {
		this.eMail = eMail;
	}

	public String getAlternateEMail() {
		return alternateEMail;
	}

	public void setAlternateEMail(String alternateEMail) {
		this.alternateEMail = alternateEMail;
	}

	public Date getBirthDate() {
		return birthDate;
	}

	public void setBirthDate(Date birthDate) {
		this.birthDate = birthDate;
	}

	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

}
